package com.bupt.liutong.admin.core.base;

import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;

import org.springframework.context.ApplicationContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import com.bupt.liutong.util.FileUtils;

public abstract class SpringContext implements ApplicationContext {
	
//	static{
//		try {
//			db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
//		} catch (ParserConfigurationException e) {
//			e.printStackTrace();
//		}
//	}
//	
//	private static ApplicationContext context = new FileSystemXmlApplicationContext(
//			new String[] { "G:\\Workspaces\\TestIbatis\\WebRoot\\WEB-INF\\spring\\applicationContext-config.xml" });
	private static DocumentBuilder db;
	
	private Document webConfig;
	private Document strutsConfig;
	private Document springConfig;
	
	private String webConfigPath = "/WEB-INF/web.xml";
	private String strutsConfigPath;
	private String springConfigPaths;
	
	private void setWebConfig() throws SAXException, IOException{
		webConfig = db.parse(FileUtils.getWebinfPath()+"web.xml");
		NodeList initParamList = webConfig.getElementsByTagName("init-param");
		for(int i=0; i<initParamList.getLength(); i++){
			Element initParam = (Element) initParamList.item(i);
			if("config".equals(initParam.getElementsByTagName("param-name").item(0).getTextContent())){
				strutsConfigPath = initParam.getElementsByTagName("param-value").item(0).getTextContent();
				break;
			}
		}
	}
	
//	public static ApplicationContext getInstance(){
//		return context;
//	}
	
//	public static void main(String[] args) {
//		
//	}
}
